package com.ymatou.c2clivebizer.testcase;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONObject;

import org.json.JSONArray;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.c2clivebizer.parameter.C2cBean;
import com.ymatou.c2clivebizer.service.C2cCall;
import com.ymatou.c2clivebizer.service.C2cSearchCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymttest.database.model.YmtC2CLiveActivity;
import com.ymttest.database.sqlwapper.AppDefaultWapper;
import com.ymttest.database.sqlwapper.YmtC2CLiveActivityWapper;
/**
*视频直播搜索接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_C2c{
	 private static C2cBean C2cBean;
	 private static C2cCall C2cCall;
	 private static C2cSearchCall C2cSearchCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("直播接口");
	}

	@Before
	public void caseUp() {
		C2cBean=new C2cBean();
		C2cCall=new C2cCall();
		C2cSearchCall = new C2cSearchCall();
		C2cBean.setAppkey(3);
		C2cBean.setSort("desc(yscore)");
		C2cBean.setModule("live_list");
		C2cBean.setPlatform("pc");
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(C2cCall.getOpurl());
		//Logger.generateResult();
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_C2c_001() {
		Logger.start(true,"直播搜索接口 - 搜索结果中搜索数据是否包含搜索关键字验证");
		try {
			String keyword = "百货";
			
			C2cBean.setFilter("");
			C2cBean.setFl("id,isReplay");
			C2cBean.setQuery("keyword(keyword,"+ keyword + ")");
			C2cCall.setData(C2cBean);
			
			C2cCall.callService();
		
			List<HashMap<String, String>> hists = new ArrayList<HashMap<String, String>>();
			 hists = C2cCall.getHitsList();
			
			Logger.verifyEquals("OK", C2cCall.getStatus(), "验证接口返回状态");
			Logger.verifyEquals(C2cCall.getTotal(), hists.size(), "验证接口返回数量 和 数据库 中查出的数据数量");
			// 验证数据库
			List<YmtC2CLiveActivity> list = new YmtC2CLiveActivityWapper().getsLiveActivity();
			// 将数据库的id加到list里
			ArrayList<Integer> id = new ArrayList<Integer>();
			for (YmtC2CLiveActivity a : list) {
				id.add(a.getIactivityid());
			}
			
			if (hists.size() > 0) {
				for (HashMap h : hists) {
					
					Logger.verifyEquals(true, h.get("remark").toString().contains(keyword), "验证每条数据中返回字符串是否包含“"+keyword+"”关键字");
				}
			}
			// 验证根据keywork 查询出来的结果集在数据库有效数据里
			if (hists.size() > 0) {
				for (HashMap h : hists) {
					// Logger.debug("id:"+h.get("id"));
					Logger.verifyEquals(true, id.contains(Integer.valueOf((String) (h.get("id")))),"验证id:" + h.get("id") + "跟数据库一致");
				}
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_C2c_002() {
		Logger.start(true,"直播搜索接口 - 验证接口返回公共数据");
		try {
			String keyword="百货";
			String beginTime = "2016-02-25 16:36:00";
			String endTime = "2016-09-27 16:00:00";
			
			C2cBean.setFilter("and(range(beginTime,"+beginTime+",null,true,true),range(endTime,null,"+endTime+",true,true))");
			C2cBean.setFl("id,isReplay");
			C2cBean.setQuery("keyword(keyword,"+keyword+")");
			C2cBean.setSort("desc(yscore)");
			C2cBean.setInfo("cookieid:asdfdsaf-11231s-fdsfsfd,userid:234235,idfa:idfavalue,imei:imeivalue");
			C2cBean.setLimit("0,10");
			
			C2cCall.setData(C2cBean);
			C2cCall.callService();			
		
		ArrayList list = C2cCall.getCommonArr();
		
		Logger.verifyEquals("OK", list.get(0), "接口返回公共数据状态");
		Logger.verifyNotNull(list.get(1),"验证took存在返回值");
		Logger.verifyNotNull(list.get(2),"验证requestId存在返回值");
		Logger.verifyNotNull(list.get(3),"验证timeOut存在返回值");
		Logger.verifyNotNull(list.get(4),"验证algorithm存在返回值");
		Logger.verifyNotNull(list.get(5),"验证hostIp存在返回值");
		Logger.verifyNotNull(list.get(6),"验证downgrade存在返回值");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_C2c_003() {
		Logger.start(false,"直播搜索接口 - 不传info参数,验证返回数据");
		try {
			String keyword="百货";
			String beginTime = "2016-02-25 16:36:00";
			String endTime = "2016-09-27 16:00:00";
			
			C2cBean.setFilter("and(range(beginTime,"+beginTime+",null,true,true),range(endTime,null,"+endTime+",true,true))");
			C2cBean.setFl("id,isReplay");
			C2cBean.setQuery("keyword(keyword,"+keyword+")");
			C2cBean.setSort("desc(yscore)");
			
			C2cCall.setData(C2cBean);
			C2cCall.callService();			
			ArrayList list = C2cCall.getCommonArr();
			
			Logger.verifyEquals("OK", list.get(0), "接口返回公共数据状态");
			Logger.verifyNotNull(list.get(1),"验证took存在返回值");
			Logger.verifyNotNull(list.get(2),"验证requestId存在返回值");
			Logger.verifyNotNull(list.get(3),"验证timeOut存在返回值");
			Logger.verifyNotNull(list.get(4),"验证algorithm存在返回值");
			Logger.verifyNotNull(list.get(5),"验证hostIp存在返回值");
			Logger.verifyNotNull(list.get(6),"验证downgrade存在返回值");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	//公共数据验证
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_C2c_004() {
		Logger.start(true,"直播搜索接口 - 检查返回结果数据是否重复");
		try {
			String keyword="直播";
			String beginTime = "2016-02-25 16:36:00";
			String endTime = "2016-09-27 16:00:00";
			
			C2cBean.setFilter("and(range(beginTime,"+beginTime+",null,true,true),range(endTime,null,"+endTime+",true,true))");
			C2cBean.setFl("id,isReplay,sellerId,remark");
			C2cBean.setQuery("keyword(keyword,"+keyword+")");
			
			C2cCall.setData(C2cBean);
			C2cCall.callService();			
			
			boolean hitsIsNull = C2cCall.getHits().toString().equals("[]");
			Logger.verifyEquals(false,hitsIsNull, "该组合条件应该有返回数据");
			if(hitsIsNull != true){
			
				JSONArray hitsAry = C2cCall.getHits();
				//JSONObject hitsListObject = JSONObject.fromObject(hitsList);
				List<Integer> list = new ArrayList<Integer>();
				
				for (int i = 1; i <= hitsAry.length(); i++) {
					
					String ids = hitsAry.get(i - 1).toString();
					JSONObject json = JSONObject.fromObject(ids);
					int id = json.getInt("id");
					
					if (list.contains(id) == true) {

						Logger.verifyEquals(false, list.contains(id), "验证第" + i+ "条返回数据的id存在重复值" + id);

					}else{
						Logger.verifyEquals(false, list.contains(id), "验证第" + i+ "条返回数据的id不存在重复值" + id);
						list.add(id);
					}
					
				}
				
			}
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_C2c_005() {
		Logger.start(false,"直播搜索接口 - 搜索关键字为空，验证返回数据");
		try {
			String keyword=null;
			
			C2cBean.setFilter("");
			C2cBean.setFl("id,isReplay");
			C2cBean.setQuery("keyword(keyword,"+keyword+")");
			
			C2cCall.setData(C2cBean);
			C2cCall.callService();			
			Logger.comment("c2clivebizerCall send:" + C2cCall.getEntityString());
			Logger.comment("c2clivebizerCall response:" + C2cCall.getReturnData());
			
			ArrayList list = C2cCall.getCommonArr();
			
			Logger.verifyEquals("OK", list.get(0), "接口返回公共数据状态");
			Logger.verifyNotNull(list.get(1),"验证took存在返回值");
			Logger.verifyNotNull(list.get(2),"验证requestId存在返回值");
			Logger.verifyNotNull(list.get(3),"验证timeOut存在返回值");
			Logger.verifyNotNull(list.get(4),"验证algorithm存在返回值");
			Logger.verifyNotNull(list.get(5),"验证hostIp存在返回值");
			Logger.verifyNotNull(list.get(6),"验证downgrade存在返回值");
				
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_C2c_006() {
		
		Logger.start(false,"直播搜索接口 - 添加异常时间范围检索，验证返回数据");
		
		try {
			String keyword="直播";
			String beginTime = "2016-02-30 16:36:00";
			String endTime = "2016-09-27 16:00:00";
			
			C2cBean.setFilter("and(range(beginTime,"+beginTime+",null,true,true),range(endTime,null,"+endTime+",true,true))");
			C2cBean.setFl("id,isReplay");
			C2cBean.setQuery("keyword(keyword,"+keyword+")");
			C2cBean.setSort("desc(yscore)");
			
			C2cCall.setData(C2cBean);
			C2cCall.callService();	
			
			boolean hitsIsNull = C2cCall.getHits().toString().equals("[]");
			
			Logger.verifyEquals(true, hitsIsNull, "检索时间异常情况下，接口返回数据为空");
			
			ArrayList list = C2cCall.getCommonArr();
			
			Logger.verifyEquals("OK", list.get(0), "检索时间异常情况下，接口不会崩溃");
			Logger.verifyNotNull(list.get(1),"验证took存在返回值");
			Logger.verifyNotNull(list.get(2),"验证requestId存在返回值");
			Logger.verifyNotNull(list.get(3),"验证timeOut存在返回值");
			//Logger.verifyNotNull(list.get(4),"验证algorithm存在返回值");
			Logger.verifyNotNull(list.get(5),"验证hostIp存在返回值");
			Logger.verifyNotNull(list.get(6),"验证downgrade存在返回值");
				
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_C2c_007() {
		Logger.start(false,"直播搜索接口 - 无返回数据的异常情况检查");
		try {
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
			String nowTime = df.format(new Date());
			
			String keyword="百货";
			String beginTime = nowTime;
			String endTime = nowTime;
			//时间检索条件传入当前时间，肯定是没有数据的
			C2cBean.setFilter("and(range(beginTime,"+beginTime+",null,true,true),range(endTime,null,"+beginTime+",true,true))");
			C2cBean.setFl("id,isReplay");
			C2cBean.setQuery("keyword(keyword,"+keyword+")");
			C2cBean.setSort("desc(yscore)");
			
			C2cCall.setData(C2cBean);
			C2cCall.callService();			
			
			boolean hitsIsNull = C2cCall.getHits().toString().equals("[]");

			Logger.verifyEquals(true, hitsIsNull, "没有满足要求的数据，接口数据返回为空");
			
			ArrayList list = C2cCall.getCommonArr();
			
			Logger.verifyEquals("OK", list.get(0), "检索时间异常情况下，接口不会崩溃");
			Logger.verifyNotNull(list.get(1),"验证took存在返回值");
			Logger.verifyNotNull(list.get(2),"验证requestId存在返回值");
			Logger.verifyNotNull(list.get(3),"验证timeOut存在返回值");
			Logger.verifyNotNull(list.get(4),"验证algorithm存在返回值");
			Logger.verifyNotNull(list.get(5),"验证hostIp存在返回值");
			Logger.verifyNotNull(list.get(6),"验证downgrade存在返回值");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_C2c_008() {
		
		Logger.start(false,"直播搜索接口 - 不设置排序情况下，数据验证");
		
		try {
			
			String keyword="直播";
			String beginTime = "2016-02-25 16:36:00";
			String endTime = "2016-09-27 16:00:00";
			//时间检索条件传入当前时间，肯定是没有数据的
			C2cBean.setFilter("and(range(beginTime,"+beginTime+",null,true,true),range(endTime,null,"+endTime+",true,true))");
			C2cBean.setFl("id,isReplay");
			C2cBean.setQuery("keyword(keyword,"+keyword+")");
			
			C2cCall.setData(C2cBean);
			C2cCall.callService();			
			
			boolean hitsIsNull = C2cCall.getHits().toString().equals("[]");
			if(hitsIsNull){
				Object hitList = C2cCall.getHits();
				Logger.debug(hitList);
			}

			ArrayList list = C2cCall.getCommonArr();
			
			Logger.verifyEquals("OK", list.get(0), "检索时间异常情况下，接口不会崩溃");
			Logger.verifyNotNull(list.get(1),"验证took存在返回值");
			Logger.verifyNotNull(list.get(2),"验证requestId存在返回值");
			Logger.verifyNotNull(list.get(3),"验证timeOut存在返回值");
			Logger.verifyNotNull(list.get(4),"验证algorithm存在返回值");
			Logger.verifyNotNull(list.get(5),"验证hostIp存在返回值");
			Logger.verifyNotNull(list.get(6),"验证downgrade存在返回值");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_C2c_009() {
		Logger.start(true,"按大洲搜索接口-返回状态");
		try {
			//TODO 补全case代码
			//org.junit.Assert.fail();
			C2cBean.setFilter("");
			C2cBean.setFl("countryGroupName,sellerId,isReplay,iSort,countryGroupId");
			// 1:北美，2：欧洲，3：亚洲，4：澳新
			C2cBean.setQuery("term(countryGroupId,3)");//countryGroupId表示大州所代表的id值
			C2cCall.setData(C2cBean);
			C2cCall.callService();			
			
			Logger.verifyEquals("OK",C2cCall.getStatus(), "按大州搜索调用成功");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_C2c_010() {
		Logger.start(true,"按大洲搜索接口-检查数据是否为条件中的州数据");
		try {
			//TODO 补全case代码
			//org.junit.Assert.fail();
			C2cBean.setFilter("");
			C2cBean.setFl("countryGroupName,sellerId,isReplay,iSort,countryGroupId");
			// 1:北美，2：欧洲，3：亚洲，4：澳新
			String countryGroupId = "3";
			C2cBean.setQuery("term(countryGroupId,"+countryGroupId+")");//countryGroupId表示大州所代表的id值
			C2cCall.setData(C2cBean);
			C2cCall.callService();			
			
			List<HashMap<String, String>> hists = new ArrayList<HashMap<String, String>>();
			 hists = C2cCall.getHitsList();
			
			Logger.verifyEquals("OK", C2cCall.getStatus(), "验证接口返回状态");
			//Logger.verifyEquals(C2cCall.getTotal(), hists.size(), "验证接口返回数量 和 数据库 中查出的数据数量");
			// 验证数据库
			List<YmtC2CLiveActivity> list = new YmtC2CLiveActivityWapper().getsLiveActivity();
			
			// 将数据库的id加到list里
			ArrayList<Integer> id = new ArrayList<Integer>();
			for (YmtC2CLiveActivity a : list) {
				id.add(a.getIactivityid());
			}
			
			if (hists.size() > 0) {
				for (HashMap h : hists) {
					
					Logger.verifyEquals(true, h.get("countryGroupId").toString().contains(countryGroupId), "验证每条数据中返回字符串是否包含“"+countryGroupId+"”关键字");
				}
			}
			// 验证根据keywork 查询出来的结果集在数据库有效数据里
			if (hists.size() > 0) {
				for (HashMap h : hists) {
					
					Logger.verifyEquals(true, id.contains(Integer.valueOf((String) (h.get("id")))),"验证id:" + h.get("id") + "跟数据库一致");
				}
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_C2c_011() {
		Logger.start(true,"增加时间过滤条件，验证返回数据");
		try {
			String beginTime = "2016-02-25 16:36:00";
			String endTime = "2016-09-27 16:00:00";
			C2cBean.setFilter("and(range(beginTime,"+beginTime+",null,true,true),range(endTime,null,"+endTime+",true,true))");
			C2cBean.setFl("id,isReplay,beginTime,endTime");
			C2cBean.setQuery("keyword(keyword,日本)");
			C2cCall.setData(C2cBean);
			C2cCall.callService();			
			
			Logger.verifyEquals("OK",C2cCall.getStatus(), "增加时间过滤调用成功");
			
			JSONArray hitsAry = C2cCall.getHits();
			//long nowTime = new Date().getTime();
			
			for (int i = 1; i <= hitsAry.length(); i++) {

				String info = hitsAry.get(i - 1).toString();
				JSONObject infoAry = JSONObject.fromObject(info);
				String times = (String) infoAry.get("endTime");
				String startTime = (String) infoAry.get("beginTime");
				// 将string转换成Date类型
				DateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				//将接口返回时间转换成date类型
				Date jEndTime = time.parse(times);
				Date jStartTime = time.parse(startTime);
				//将传入参数时间转换成date类型
				Date cEndTime = time.parse(endTime);
				Date cStartTime = time.parse(beginTime); 

				// 将时间转换成时间戳
				long jEndTimes = jEndTime.getTime();
				long jBeginTimes = jStartTime.getTime();
				long cEndTimes = cEndTime.getTime();
				long cStartTimes = cStartTime.getTime();
			
				Logger.verifyEquals(true, cStartTimes < jBeginTimes, "验证第" + i+ "条记录直播开始时间大于传入的开始时间");
				Logger.verifyEquals(true, jEndTimes < cEndTimes, "验证第" + i+ "条记录直播结束时间小于传入的结束时间");

			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_C2c_012() {
		Logger.start(true,"按关键字搜索-返回记录数");
		try {
			//TODO 补全case代码
			//org.junit.Assert.fail();
			C2cBean.setFilter("");
			C2cBean.setFl("id,isReplay");
			C2cBean.setQuery(null);
			C2cCall.setData(C2cBean);
			C2cCall.callService();		
			
			//访问索引文件
			C2cSearchCall.setUrl("http://es.ymatou.com:19200/c2clive/_search?size=100&q=validProductStatus:4");
			C2cSearchCall.callService();	
			
			//获取索引文件中的总记录数
			Integer indexTotal = (Integer) C2cSearchCall.getData().get("total");
			
			Logger.comment("c2clivebizerCall send:" + C2cCall.getEntityString());
			Logger.comment("c2clivebizerCall response:" + C2cCall.getReturnData());
			//查询出的数据还需要过滤掉未认证的买手
			Logger.verifyEquals(indexTotal,C2cCall.getTotal(), "接口返回记录数");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_C2c_013() {
		Logger.start(true,"直播区域统计接口-返回状态");
		try {
			//TODO 补全case代码
			//org.junit.Assert.fail();
			C2cBean.setPlatform("appbuyer");
			C2cBean.setModule("mainhome");
			C2cBean.setStat("term(countryGroupId)");
			C2cBean.setLimit("0,10");
			C2cBean.setInfo("timenow:20160127143200,cookieid:6500D309-609D-4CAE-8A35-50A7972361C5,userid:3592231");
			C2cCall.setData(C2cBean);
			C2cCall.callService();			
			Logger.comment("c2clivebizerCall send:" + C2cCall.getEntityString());
			Logger.comment("c2clivebizerCall response:" + C2cCall.getReturnData());
			Logger.verifyEquals("OK",C2cCall.getStatus(), "直播区域统计接口返回状态ok");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_C2c_014() {
		Logger.start(true,"直播区域统计接口-比较时间及状态验证返回id值有效性验证 ");
		try {
			//TODO 补全case代码
			//org.junit.Assert.fail();
			C2cBean.setPlatform("appbuyer");
			C2cBean.setModule("mainhome");
			C2cBean.setStat("term(countryGroupId)");
			C2cBean.setLimit("0,10");
			C2cBean.setInfo("timenow:20160329143200,cookieid:6500D309-609D-4CAE-8A35-50A7972361C5,userid:3592231");
			C2cCall.setData(C2cBean);
			C2cCall.callService();			
			
			//得到hits里的所有id，此id为iactivityid
			JSONArray Hits = C2cCall.getHits();
			//取第一条查看是否有效
			String hits=Hits.get(0).toString();
			JSONObject json=JSONObject.fromObject(hits);
			String id = json.getString("id");
			//查找Ymt_Activity表中的这条记录
			List<Map> activityTime = new AppDefaultWapper().getActivityTime(id);
			//比较当前时间是否比小于结束时间
			Date time= (Date) activityTime.get(0).get("dEndTime");
			long nowTime = new Date().getTime();
			long endTime = time.getTime();
			
			//比较两个时间点
			Logger.verifyEquals(true, nowTime<endTime, "已过期的直播也存在了！");
			
			//取状态值
			int iaction =(Integer) activityTime.get(0).get("iAction");
			//比较状态值
			Logger.verifyEquals(1,iaction, "状态不为1的直播也存在了！");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_C2c_015() {
		Logger.start(true,"直播区域统计接口-返回值是否存在重复性 ");
		try {
			//TODO 补全case代码
			//org.junit.Assert.fail();
			C2cBean.setPlatform("appbuyer");
			C2cBean.setModule("mainhome");
			C2cBean.setStat("term(countryGroupId)");
			C2cBean.setLimit("0,100");
			C2cBean.setInfo("timenow:20160129143200,cookieid:6500D309-609D-4CAE-8A35-50A7972361C5,userid:3392231");
			C2cCall.setData(C2cBean);
			C2cCall.callService();			
			
			//得到hits里的所有id，此id为iactivityid
			JSONArray hits = C2cCall.getHits();
			List<Integer> list = new java.util.ArrayList<Integer>();
			
			for(int i=0;i<hits.length();i++){
				
			String ids	= hits.get(i).toString();
			JSONObject json=JSONObject.fromObject(ids);
			int id = json.getInt("id");
			if(!list.contains(id)){//判断是否包含存在的值，包含返回true
				list.add(id);
			}
			
			}
			Logger.verifyEquals(list.size(),hits.length(), "是否存在重复值");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_C2c_016() {
		Logger.start(true,"直播区域统计接口-是否返回groupid ");
		try {
			//TODO 补全case代码
			//org.junit.Assert.fail();
			C2cBean.setPlatform("appbuyer");
			C2cBean.setModule("mainhome");
			C2cBean.setStat("term(countryGroupId)");
			C2cBean.setLimit("0,0");
			C2cBean.setInfo("timenow:20160129143200,cookieid:6500D309-609D-4CAE-8A35-50A7972361C5,userid:3392231");
			C2cCall.setData(C2cBean);
			C2cCall.callService();			
			
			boolean statsRestul = C2cCall.statsRestul();
			Logger.verifyEquals(true, statsRestul, "返回接口是否包含stat的key值");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_C2c_017() {
		Logger.start(true,"直播区域统计接口-返回统计值是否正确 ");
		try {
			//TODO 补全case代码
			//org.junit.Assert.fail();
			C2cBean.setPlatform("appbuyer");
			C2cBean.setModule("mainhome");
			C2cBean.setStat("term(countryGroupId)");
			C2cBean.setLimit("0,0");
			C2cBean.setInfo("timenow:20160129143200,cookieid:6500D309-609D-4CAE-8A35-50A7972361C5,userid:3392231");
			C2cCall.setData(C2cBean);
			C2cCall.callService();			
			
			//得到接口返回total值
			
			 int total = C2cCall.getTotal();
			//得到hits里的所有id，此id为iactivityid
			 boolean statsRestul = C2cCall.statsRestul();
			 if(statsRestul==false){
				 Logger.verifyEquals(true,false, "返回接口没有包含stat的key值无法继续验证");
			 }else{
				 Object groupAry = C2cCall.getStats();
				 
					JSONObject json=JSONObject.fromObject(groupAry);
					
					JSONObject activityNumAry= (JSONObject) json.get("countryGroupId");
					int num = 0;
					//用Iterator迭代器遍历取值
					Iterator iterator = activityNumAry.keys();
					while(iterator.hasNext()){
					     String	key = (String) iterator.next();
					     String value = activityNumAry.getString(key);
					     int i =Integer.parseInt(value);
					     num = i+num;
					     
					}
					
					Logger.verifyEquals(total,num, "州统计值相加与总数是否相等");
					
			 }
			 
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
}